# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: AlexWMF <alexxwmf@gmail.com>

_realname=liblastfm
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.1.0
pkgrel=2
pkgdesc="A Qt C++ library for the Last.fm webservices https://www.last.fm"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('Boost')
url="https://www.last.fm/download"
depends=("${MINGW_PACKAGE_PREFIX}-qt5-base"
        "${MINGW_PACKAGE_PREFIX}-fftw"
        "${MINGW_PACKAGE_PREFIX}-libsamplerate")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake")
options=(!strip staticlibs !buildflags)
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/lastfm/liblastfm/archive/${pkgver}.tar.gz"
        versioned-dlls-mingw.patch)
sha256sums=('f61f0daa384e081a8f2bd2f7a2148babff22696e5b72ecdac86940a10100b1c8'
            '32e77ca2e80ce08cb4a8c9d11daf4618ec87177fa8e986737d720eb4feea7485')

prepare() {
    cd ${srcdir}/${_realname}-${pkgver}
    patch -p0 -i ${srcdir}/versioned-dlls-mingw.patch
}

build() {
  [[ -d "${srcdir}"/build-${MSYSTEM} ]] && rm -rf "${srcdir}"/build-${MSYSTEM}
  mkdir ${srcdir}/build-${MSYSTEM}
  cd ${srcdir}/build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DCMAKE_CXX_STANDARD=14 \
    -DBUILD_TESTS=False \
    -Wno-dev \
    ${srcdir}/${_realname}-${pkgver}

  make ${MAKEFLAGS} # VERBOSE=1
}

package() {
  cd ${srcdir}/build-${MSYSTEM}
  make DESTDIR=${pkgdir} -j1 install
}
